#include "stinger.h"

//获取顶点的类型映射
int get_vertex_type_mapping(std::string vertex_type) {
    for (int i = 0; i < stinger_root->max_vtype_num; i++) {
        if (stinger_root->vertex_type_map[i] == vertex_type) {
            return i;
        }
    }
    return -1;
}

//获取边的类型映射
int get_edge_type_mapping(std::string type) {
    for (int i = 0; i < stinger_root->max_etype_num; i++) {
        if (stinger_root->edge_type_map[i] == type) {
            return i;
        }
    }
    return -1;
}

//添加一个顶点类型映射:不能添加相同的类型:表示失败，返回-1
int add_vertex_type_mapping(std::string vertex_type) {
    int res = get_vertex_type_mapping(vertex_type);
    if (res != -1) {
        return -1; //表示添加失败
    }
    stinger_root->vertex_type_map[stinger_root->max_vtype_num] = vertex_type;
    stinger_root->max_vtype_num.get_rw() += 1;
    return stinger_root->max_vtype_num - 1;
}

//添加一个边类型映射:不能添加相同的类型:表示失败，返回-1
int add_edge_type_mapping(std::string edge_type) {
    int res = get_edge_type_mapping(edge_type);
    if (res != -1) {
        return -1; //表示添加失败
    }
    stinger_root->edge_type_map[stinger_root->max_etype_num] = edge_type;
    stinger_root->max_etype_num.get_rw() += 1;
    return stinger_root->max_etype_num - 1;
}

//通过顶点的type找到name
bool get_vertex_name_mapping(int vertex_type, std::string * vertex_type_name) {

    if (vertex_type >= stinger_root->max_vtype_num || vertex_type < 0) {
        *vertex_type_name = "";
        return false;
    }
    *vertex_type_name = stinger_root->vertex_type_map[vertex_type].c_str();
    return true;
}

//通过边的type找到name
bool get_edge_name_mapping(int edge_type, std::string * edge_type_name) {

    if (edge_type >= stinger_root->max_etype_num || edge_type < 0) {
        *edge_type_name = "";
        return false;
    }
    *edge_type_name = stinger_root->edge_type_map[edge_type].c_str();
    return true;
}

